//===============================
//  功能 ：备注 
//  作者 ：上中野辅亚瑟王 
//  创建时间 ：2024-08-13  16-27-24 
//  Unity版本  ：2019.4.35f1 
//  变更时间 :  2024-08-13  16-27-24 
//===============================





using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace ZS.U3D.BASE.Cast
{
    public interface ICast
    {
        float RemainingTime { get; set; }
        void Draw();
    }

    /// <summary>
    /// 标签
    /// </summary>
    public class LabelCast : ICast
    {
        public string label;
        public Vector3 center;
        public Color color;

        private float remainingTime;

        public float RemainingTime
        {
            get { return remainingTime; }
            set { remainingTime = value; }
        }

        public void Draw()
        {
#if UNITY_EDITOR
            var style = new GUIStyle();
            style.normal.textColor = color;
            style.fontSize = 20;
            Handles.Label(center, label, style);
#endif
        }
    }

    /// <summary>
    /// 圆形
    /// </summary>
    public class CircleCast : ICast
    {
        public Vector3 center;
        public float radius;
        public Vector3 direction;
        public Color color;

        private float remainingTime;

        public float RemainingTime
        {
            get { return remainingTime; }
            set { remainingTime = value; }
        }

        public void Draw()
        {
#if UNITY_EDITOR
            Handles.color = color;
            Handles.DrawWireDisc(center, direction, radius);
#endif
        }
    }

    /// <summary>
    /// 球形
    /// </summary>
    public class SphereCast : ICast
    {
        public Vector3 center;
        public float radius;
        public Color color;

        private float remainingTime;

        public float RemainingTime
        {
            get { return remainingTime; }
            set { remainingTime = value; }
        }

        public void Draw()
        {
#if UNITY_EDITOR
            Gizmos.color = color;
            Gizmos.DrawWireSphere(center, radius);
#endif
        }
    }

    /// <summary>
    /// 胶囊体
    /// </summary>
    public class CapsuleCast : ICast
    {
        public Vector3 bot;
        public Vector3 top;
        public float radius;
        public Color color;

        private float remainingTime;

        public float RemainingTime
        {
            get { return remainingTime; }
            set { remainingTime = value; }
        }

        public void Draw()
        {
#if UNITY_EDITOR
            Gizmos.color = color;
            Gizmos.DrawWireSphere(bot, radius);
            Gizmos.DrawWireSphere(top, radius);

            for (int j = 0; j < 4; j++)
            {
                float x = j == 0 ? 1 : j == 2 ? -1 : 0;
                float y = j == 1 ? 1 : j == 3 ? -1 : 0;

                Vector3 offset = new Vector3(x, 0, y) * radius;
                Vector3 start = bot + offset;
                Vector3 end = top + offset;

                Gizmos.DrawLine(start, end);
            }
#endif
        }
    }

    public class ArrowCast : ICast
    {
        public Vector3 center;
        public Vector3 direction;
        public float length;
        public Color color;

        private float remainingTime;

        public float RemainingTime
        {
            get { return remainingTime; }
            set { remainingTime = value; }
        }

        public void Draw()
        {
#if UNITY_EDITOR
            Handles.color = color;
            Handles.ArrowHandleCap(0, center, Quaternion.LookRotation(direction), length, EventType.Repaint);
#endif
        }
    }

    public class LineCast : ICast
    {
        public Vector3 start;
        public Vector3 end;
        public Color color;

        private float remainingTime;

        public float RemainingTime
        {
            get { return remainingTime; }
            set { remainingTime = value; }
        }

        public void Draw()
        {
#if UNITY_EDITOR
            Handles.color = color;
            Handles.DrawLine(start, end);
#endif
        }
    }
}


